<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        const xhr=new XMLHttpRequest();
        xhr.addEventListener("progress", function(e){
            console.log("progress",e)
        });
        // 请求完成了才执行
        xhr.addEventListener("load" , function(e){
            const {target}=e;
            target
            console.log("load" ,target)
        });
        xhr.addEventListener("error", function(e){
            console.log("error",e)
        }  );
        xhr.addEventListener("abort", function(e){
            console.log("abort", e)
        });

        xhr.open('get','https://jsonplaceholder.typicode.com/posts')
        // 这个比load事件更快执行
        //readyState属性变化了才执行
        xhr.onreadystatechange = function () {
            if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                console.log('onreadystatechange',xhr)
            }
        }
        let body=null
        xhr.send(body);

        function httpGet(url,param,options){

        }

        function httpPost(url,param,options){

        }
        
    </script>
    
</body>
</html>